<template>
	<view class="">
		<view class="tipBox">为保证您的账户安全，请确定接收人信息</view>
		<view class="pagesBox">
			<view class="pagesMain">
				<view class="popupInput">
					<view class="inputTitle">接收人</view>
					<view class="myInputBox">
						<view class="myInputMain">
							<u-input v-model="params.phone" placeholder="请输入接收人账号/手机号" :custom-style="inputStyle" :clearable="false" style="flex: 1;" type="text" :border='false' :height="96"></u-input>
							<view class="inputBtn" hover-class="inputHover" @click="query">查询</view>
						</view>
					</view>
				</view>
				<view class="popupInput">
					<view class="inputTitle">接收信息</view>
					<u-input v-model="acceptInfo" :placeholder="acceptInfo" :clearable="false" :custom-style="inputStyle" type="textarea" disabled :border='false' :height="96"></u-input>
				</view>
				<view class="popupInput">
					<view class="inputTitle">转让积分数量</view>
					<u-input v-model="params.num" placeholder="请输入转让积分数量" :clearable="false" :custom-style="inputStyle" type="digit" :border='false' :height="96"></u-input>
				</view>
				<view class="popupInput">
					<view class="inputTitle">支付密码</view>
					<u-input v-model="params.pay_pwd" placeholder="请输入支付密码" :clearable="false" :custom-style="inputStyle" type="digit" :border='false' :height="96"></u-input>
				</view>
				<!-- <view class="popupInput">
					<view class="inputTitle">验证码</view>
					<view class="myInputBox">
						<view class="myInputMain">
							<u-input v-model="params.verify_code" placeholder="请输入验证码" :custom-style="inputStyle" :clearable="false" style="flex: 1;" type="number" :border='false' :height="96"></u-input>
							<view class="codeBox" @click="getCodeBefore">{{tips}}</view>
						</view>
					</view>
				</view> -->
			</view>
			<my-submitBtn :isFixed="false" btnText="下一步" @click="submitBefore"></my-submitBtn>
		</view>
		<my-explainPopup :show="showTip" :type="2" @submit="submitHandle" @cancal="showTip = false" dataTitle="积分账户转让提示" :dataDetail="dataDetail"></my-explainPopup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl:this.$baseUrl,
				inputStyle:{background:'#F7F8FA',borderRadius:'6rpx',paddingLeft:'24rpx'},
				keysword:"",
				params:{
					phone:'',
					num:'',
					pay_pwd:"",
					// verify_code:""
				},
				time:'',
				acceptInfo:"",
				// 验证码
				tips:'获取验证码',
				daoJiShi:60,
				// 获取验证码倒计时的执行事件
				timeCode:'',
				time:'',
				headInfo:"",
				showTip:false,
				dataDetail:"1、转让成功后，将从本账户积分中扣除相应的积分账户转让数量。\n2、转让操作不可撤销，因个人原因导致转让错误等问题将由本账户持有者自行承担。\n3、请再次核对【接收人】信息无误并确认是否继续操作。"
			};
		},
		onLoad(options) {
			this.getUserInfo()
		},
		methods:{
			async getUserInfo(){
				let res = await uni.$http('POST','user/userInfo');
				console.log("用户信息",res);
				if(res.code == 1){
					this.headInfo = res.data;
				}else if(res.msg.includes('登录')){
					uni.setStorageSync('token',0);
				}
			},
			// 获取验证码
			getCodeBefore(){
				if(this.timeCode){
					uni.$u.toast(`请在${this.daoJiShi}秒后再次发送`);
				}else{
					uni.showLoading({
						title: '正在获取验证码',
						mask:true
					});
					setTimeout(()=>{
						this.getCode()
					},500)
				}
			},
			async getCode(){
				let res = await uni.$http('POST','user/sendSmsVerify',{phone:this.headInfo.phone});
				console.log('获取验证码',res);
				uni.hideLoading()
				if(res.code == 1){
					this.timeCode = setInterval(()=>{
						if(this.daoJiShi <= 0){
							this.daoJiShi = 60;
							this.tips = '获取验证码'
							clearInterval(this.timeCode);
						
							this.timeCode = '';
						}else{
							this.daoJiShi = this.daoJiShi-1;
							this.tips = `重新获取(${this.daoJiShi})`
						}
					},1000)
				}else{
					uni.$u.toast(res.msg)
				}
			},
			submitBefore(){
				if(!this.params.phone){
					uni.$u.toast(`请输入接收人账号或手机号`);
				}else if(!this.acceptInfo){
					uni.$u.toast(`请先查询接收人信息`);
				}else  if(!this.params.num){
					uni.$u.toast(`请输入转让积分数量`);
				}else  if(!this.params.pay_pwd){
					uni.$u.toast(`请输入支付密码`);
				}else {
					this.showTip = true;
				}
			},
			submitHandle(){
				this.showTip = false;
				uni.showLoading({
					title:"加载中",
					mask:true
				})
				setTimeout(()=>{
					this.submit()
				},700)
			},
			async submit(){
				let res = await uni.$http('POST','score/transfer',this.params)
				console.log('积分转让',res);
				uni.hideLoading()
				uni.$u.toast(res.msg)
				if(res.code == 1){
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				}else if(res.msg.includes('请设置支付密码')){
					setTimeout(()=>{
						uni.navigateTo({
							url:"/pagesIndex/changePwd/changePwd?type=3"
						})
					},1000)
				}
			},
			async query(){
				if(!this.params.phone){
					uni.$u.toast('请输入接收人账号或手机号')
				}else{
					uni.showLoading({
						title:"查询中",
						mask:true
					})
					let res = await uni.$http('POST','score/selectInfo',{keysword:this.params.phone})
					console.log('查询用户信息',res);
					uni.hideLoading()
					if(res.code == 1){
						this.acceptInfo = res.data.nick_name+"/"+res.data.phone+"/"+res.data.account
					}else{
						uni.$u.toast(res.msg)
					}
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.tipBox{
		height: 120rpx;
		color: #2BA777;
		background-color: #e8f0f2;
		display: flex;
		justify-content: center;
		align-items: center;
	}
.pagesBox{
	position: relative;
	.pagesMain{
		background-color: #fff;
		// border-radius: 12rpx;
		padding: 32rpx;
		margin-bottom: 36rpx;
		.popupInput{
			margin-bottom: 32rpx;
			position: relative;
			&:last-of-type{
				margin-bottom: 0rpx;
			}
			.inputTitle{
				font-weight: 600;
				font-size: 28rpx;
				color: #16202B;
				margin-bottom: 10rpx;
			}
			// 自定义输入框
			.myInputBox{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.myInputMain{
					width: 100%;
					height: 96rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #000;
					background-color: #F7F8FA;
					// border: 2rpx solid #dcdfe6;
					border-radius: 16rpx;
					// padding: 0 24rpx;
					padding-right: 24rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.codeBox{
						font-size: 26rpx;
						color: #2BA777;
					}
					.inputBtn{
						font-size: 24rpx;
						color: #fff;
						background-color: #2BA777;
						border-radius: 16rpx;
						padding: 12rpx 36rpx;
					}
					.inputHover{
						background-color: #37d898;
					}
				}
			}
			// 字数
			.textNum{
				color: #A1A5AA;
				position: absolute;
				bottom: 12rpx;
				right: 16rpx;
			}
		}
	}
}
</style>
<style>
	page{
		background-color: #F7F8FA;
	}
</style>